<template>
    <h1>这是理财添加页面</h1>

    <table>
        <tr>
            <td>项目名称</td>
            <td>
                <input type="text" v-model="Invest.T_Name" placeholder="请输入项目名称">
            </td>
        </tr>

        <tr>
            <td>年收益</td>
            <td>
                <input type="text" v-model="Invest.T_Bougin" placeholder="请输入年收益">
            </td>
        </tr>

        <tr>
            <td>最低金额</td>
            <td>
                <input type="text" v-model="Invest.T_Ymoney" placeholder="请输入最低金额">
            </td>
        </tr>

        <tr>
            <td>风险等级</td>
            <td>
                <input type="text" v-model="Invest.T_Fxian" placeholder="请输入风险等级">
            </td>
        </tr>

        <tr>
            <td colspan="2">
                <input type="button" value="添加" @click="AddData">
            </td>
        </tr>

    </table>

</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import axios from 'axios';

const Invest = ref({
    T_Name:'',
    T_Bougin:'',
    T_Ymoney:'',
    T_Fxian:'',
})


const router = useRouter();

const AddData = () => {
    axios({
        method:'post',
        url:'http://localhost:53922/api/Invest/AddInvest',
        data:{
            T_Name:Invest.value.T_Name,
            T_Bougin:Invest.value.T_Bougin,
            T_Ymoney:Invest.value.T_Ymoney,
            T_Fxian:Invest.value.T_Fxian,
        }
    })
    .then(function(res){
      if(res.data==1){
          alert('添加成功');
          router.push('/ShowInvest');
      }  
      else if(res.data==-1){
        alert('理财名称存在');
        return;
      }
      else{
          alert('添加失败');
          return;
      }
    })
}

</script>